package com.ewzj.bigdata.mvp.ui.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ewzj.bigdata.R;
import com.ewzj.bigdata.mvp.model.entity.resbean.CollectBean;

import java.util.List;

/**
 * Author:zhangjing
 * Time:2018/3/27  下午5:38
 * Name: this is ListCollectAdapter
 * Email:zhangjingworkmol@163.com
 */

public class ListCollectAdapter extends BaseQuickAdapter<CollectBean,BaseViewHolder>{
    public CollectBean getSelectItem() {
        return selectItem;
    }

    public void setSelectItem(CollectBean selectItem) {
        this.selectItem = selectItem;
    }

    private CollectBean selectItem;
    public ListCollectAdapter(@Nullable List<CollectBean> data) {
        super(R.layout.collect_itemlist, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, CollectBean item) {
        helper.<TextView>getView(R.id.tv_collectname).setText(item.getTitle());
        if (item.getSelected()){
            selectItem=item;
            helper.getView(R.id.iv_selectstatu).setVisibility(View.VISIBLE);
        }else {
            helper.getView(R.id.iv_selectstatu).setVisibility(View.GONE);
        }
        helper.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (int i = 0; i < mData.size(); i++) {
                    mData.get(i).setSelected(false);
                }
                selectItem=item;
                item.setSelected(true);
                notifyDataSetChanged();
            }
        });
    }
}
